<?php

 //if there is an ID given...
        if ($_GET['id']) {
            //get the id, put it into a variable, cast to an INT
            //(for security purposes)
            $id = (int)$_GET['id'];
			$id = secure($id);
			
            $query = mysql_query("SELECT * FROM pages WHERE cat_id = '$id' AND is_validated = '1'") or
                die(mysql_error());

            //if no results, show that there are no tutorials
            //for that category
            if (mysql_num_rows($query) == 0) {
                echo "No tutorials for this category yet!";
            }
            //else, there is..show em
            else {
                echo "<h1>Tutorials</h1>";
                //loop through the tutorials
                //show all tutorials
                echo "<table class='table' border='1' width='100%'>
<tr> <th>Page	</th>	 <th>Date Published</th> 	<th>Views</th>  <th>&nbsp;</th></tr>";
                while ($row = mysql_fetch_array($query)) {
                    echo "
                    <tr>
                       
                        <td><b><a href='$self?action=viewpage&id=$row[id]'>$row[title]</a></b></td>
                    
                        
                        <td><b>$row[date_submitted]</b></td>
                    
                        
                        <td>$row[views]</td>
                    
                        
                    
                        <td colspan='2'><center><b><a href='$self?action=viewpage&id=$row[id]'>View</a></b></center></td>
                    
                        
                    </tr>
                ";
                }
                echo "</table>";
            }
        } else {
		
		$findcats = mysql_query("SELECT * FROM page_categories");
		while ($cat = mysql_fetch_array($findcats)) {
		
		$catid = $cat['id'];
		$catname = $cat['category'];
		$catdisc = $cat['description'];
		
		echo "<a href='index.php?action=category&id=$catid'>$catname</a><br />$catdisc<br /><br />";
		
		}
		
         
        }
?>